﻿Public Class ChoixDossierMedical_CTRL
    Implements IDisposable


    Private _EDM As AniFormEntities
    Private _listeClient As List(Of Clients)
    Private _animalCourant As Animaux


#Region "cycle de vie du controleur CHoixDossierMedical"

    Public Sub New(ByVal EDM As AniFormEntities)

        _EDM = EDM
        _listeClient = New List(Of Clients)

    End Sub

    Private disposedValue As Boolean = False        ' Pour détecter les appels redondants

    ' IDisposable
    Protected Overridable Sub Dispose(ByVal disposing As Boolean)
        If Not Me.disposedValue Then
            If disposing Then
            End If

            For Each element In _listeClient
                element = Nothing
            Next
            _listeClient.Clear()
            _listeClient = Nothing
            _EDM.Dispose()
            _animalCourant = Nothing

        End If
        Me.disposedValue = True
    End Sub

    Public Sub Dispose() Implements IDisposable.Dispose
        Dispose(True)
        GC.SuppressFinalize(Me)
    End Sub

#End Region


    Public Property animalCourant() As Animaux
        Get
            Return _animalCourant
        End Get
        Set(ByVal value As Animaux)
            _animalCourant = value
        End Set
    End Property

    ''' <summary>
    ''' Procedure remplaçant la listeclient actuelle par la liste complete des clients à partir de l'EDM
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub getAllClients()

        Dim requete As IEnumerable = (From unClient In _EDM.Clients Select unClient Where unClient.Archive = False)
        _listeClient.AddRange(requete)

    End Sub

    Public ReadOnly Property listeClient() As List(Of Clients)
        Get
            Return _listeClient
        End Get
    End Property


    ''' <summary>
    ''' Procedure de recherche d'un client par son nom et prenom
    ''' </summary>
    ''' <param name="nom"></param>
    ''' <remarks></remarks>
    Public Sub rechercheClientByNom(ByVal nom As String)

        Dim requete As IEnumerable(Of Clients) = From unclient In _EDM.Clients Select unclient Where unclient.NomClient.Contains(nom) And unclient.Archive = False Distinct

        _listeClient.Clear()
        _listeClient.AddRange(requete)

    End Sub

    Public Sub rechercheClientByNomAndPrenom(ByVal nom As String, ByVal prenom As String)

        Dim requete As IEnumerable(Of Clients) = From unclient In _EDM.Clients Select unclient Where unclient.NomClient = nom And unclient.PrenomClient = prenom And unclient.Archive = False Distinct

        _listeClient.Clear()
        _listeClient.AddRange(requete)

    End Sub



    Public Function getNomCLient() As List(Of String)

        getNomCLient = New List(Of String)

        For Each client In _listeClient
            getNomCLient.Add(client.NomClient)
        Next

    End Function

    Public Function getPrenomClient() As List(Of String)

        getPrenomClient = New List(Of String)

        For Each client In _listeClient
            getPrenomClient.Add(client.PrenomClient)
        Next

    End Function

End Class
